package com.itheima.mvcconfig;


import com.itheima.exception.BusinessException;
import com.itheima.exception.SystemException;
import com.itheima.pojo.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

//@RestControllerAdvice//用于标识当前类为rest风格(json字符串)对应的异常处理器
public class ProjectExceptionAdvice {
    @ExceptionHandler(Exception.class)//统一处理Exception异常,具体的异常处理
    public Result otherException(Exception ex){
        //err 输出红色的异常信息
        System.out.println("异常处理器接收到了异常");
        ex.printStackTrace();
        System.out.println("以上为该异常的信息");
        return new Result(0,ex.getMessage());
    }

    @ExceptionHandler(BusinessException.class)//统一处理Exception异常,具体的异常处理
    public Result BusinessException(BusinessException ex){
        //err 输出红色的异常信息
        System.out.println("异常处理器接收到了异常");
        ex.printStackTrace();
        System.out.println("以上为该异常的信息");
        return new Result(0,ex.getMessage());
    }

    @ExceptionHandler(SystemException.class)//统一处理Exception异常,具体的异常处理
    public Result SystemException(SystemException ex){
        //err 输出红色的异常信息
        System.out.println("异常处理器接收到了异常");
        ex.printStackTrace();
        System.out.println("以上为该异常的信息");
        return new Result(0,"对不起,服务器忙,请稍后再试...");
    }
}
